var dashboard = angular.module("dashboardApp", ['ngAnimate','ngRoute','angular-loading-bar']);

dashboard.config(function($routeProvider, $locationProvider) {
	$routeProvider.when('/home', {
		templateUrl: base_url + "dashboard/home",
		controller: "homeCtrl"
	})
	.when('/list/:type', {
		templateUrl: base_url + "dashboard/lessonlist",
		controller: "lsListCtrl"
	})
	.when('/lscompose/:type/:lsId', {
		templateUrl: base_url + "dashboard/lessoncompose",
		controller: "lsComposeCtrl"
	})
	.when('/lscompose/lesson', {
		redirectTo: '/lscompose/lesson/untiled'
	})
	.when('/lscompose/place', {
		redirectTo: '/lscompose/place/untiled'
	})
	.when('/lscompose/person', {
		redirectTo: '/lscompose/person/untiled'
	})
	.when('/lscompose', {
		redirectTo: '/lscompose/lesson/untiled'
	})
	.when('/mapslist', {
		templateUrl: base_url + "dashboard/maps",
		controller: "mapsCtrl"
	})
	.when('/menu', {
		templateUrl: base_url + 'dashboard/menus',
		controller: "menuCtrl"
	})
	.when('/comment', {
		templateUrl: base_url + 'dashboard/comment',
		controller: "commentCtrl"
	})
	.when('/chooseTest', {
		templateUrl: base_url + 'dashboard/choosen',
		controller: "testCtrl"
	})
	.otherwise({ redirectTo: '/home' });
});

dashboard.constant('BASE_URL', base_url);

dashboard.controller('GlobalController',['$scope', '$http', '$location', '$rootScope', 
function($scope, $http, $location, $rootScope) {
	$scope.loadingView = true;

	$scope.$on('$routeChangeStart', function() {
		$scope.loadingView = true;
	});

	$scope.redirect = function(view) {
		$location.path('/' + view);
	}
}]);

dashboard.run(function($rootScope) {

	$rootScope.$on('$routeChangeSuccess', function() {
		setTimeout(function() {
			$('.main-menu').removeClass('show');
			$('.main-page').removeClass('hide-left');
			$('#topbar').removeClass('hide-left');
		}, 200);
	});
}); 


// =============================================================================
// ==================GLOBAL=FUNCTION============================================
getAlert = function(str) {
	$("#alertMessage .msg-content").html(str);
	$('#alertMessage').modal('show');
}